package com.example.demo1.service;

import com.example.demo1.Entity.CourseApplication;
import com.example.demo1.repository.CourseApplicationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class CourseApplicationServiceImpl implements CourseApplicationService {

    @Autowired
    private CourseApplicationRepository courseApplicationRepository;


    @Override
    @Transactional
    public CourseApplication Allsert(Long teacherId,
                                     String teacherName,
                                     String contactInformation,
                                     Long courseId,
                                     String courseName,
                                     Double xueFen,
                                     Double xueShi,
                                     String courseInformation) {

        // 创建实体对象
        CourseApplication courseApplication = new CourseApplication();
        courseApplication.setTeacher_id(teacherId);
        courseApplication.setTeacher_name(teacherName);
        courseApplication.setContact_information(contactInformation);
        courseApplication.setCourse_id(courseId);
        courseApplication.setCourse_name(courseName);
        courseApplication.setXue_fen(xueFen);
        courseApplication.setXue_shi(xueShi);
        courseApplication.setCourse_information(courseInformation);

        return courseApplication;
    }

    @Override
    @Transactional
    public void save_data(CourseApplication C) {
        courseApplicationRepository.save(C);
        System.out.println("插入成功！ID: " + C.getId());
    }
}
